<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>EventSource</title>
<style type="text/css">
html, body {
	width: 100%;
	height: 100%;
	margin: 0 0;
}
</style>
</head>
<body>
	<!-- HTML5 EventSource 服务端推送事件 -->

	<textarea id="oTextarea" style="width: 500px; height: 90%;"></textarea>
	<script>
		var oTextarea = document.getElementById('oTextarea');
		oTextarea.value = '';

		var appendMsg = function(msg) {
			oTextarea.value += (msg || '') + '\n';
		}

		var evtSource = new EventSource('http://localhost:9999/stream');

		evtSource.addEventListener('message', function(e) {
			console.log(e);
			appendMsg(e.data);
		});
		evtSource.addEventListener('error', function(e) {
			console.log(e);
		})
	</script>
</body>
</html>